class LoginController < ApplicationController
  layout 'layouts/standard_layout'
  def index
    
  end
  
  def error
    flash[:notice] = "Invalid username or password"
  end
  
  def login
    svcs = YAML.load_file("#{RAILS_ROOT}/config/services.yml")
    client = DrupalClient.new(svcs["Drupal"]["host"], params[:username], params[:password])
    login = client.login
    if login == 0
      redirect_to :action=>"error" 
      return
    end
    session[:username] = params[:username]
    session[:drupal_id] = params[:login]
    unless Person.find_by_username(params[:username])
      redirect_to :controller=>'profile', :action=>'edit' 
      return
    end
    redirect_to :back
  end  
  
  def logout
    session[:username] = nil
    session[:drupal_id] = nil
    redirect_to :action=>'index'
  end
end
